/*
 * HSM Proxy Project.
 * Copyright (C) 2013 FedICT.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License version
 * 3.0 as published by the Free Software Foundation.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, see 
 * http://www.gnu.org/licenses/.
 */

package be.fedict.hsm.admin.webapp;

import java.util.List;

import javax.ejb.EJB;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.inject.Named;

import be.fedict.hsm.admin.webapp.security.RolesAllowed;
import be.fedict.hsm.entity.SecurityAuditEntity;
import be.fedict.hsm.model.admin.SecurityAuditManagerBean;
import be.fedict.hsm.model.security.AdministratorRoles;

@Named("hsmProxySecurityAudit")
@RolesAllowed(AdministratorRoles.ADMINISTRATOR)
public class SecurityAuditController {

	@EJB
	private SecurityAuditManagerBean securityAuditManagerBean;

	public List<SecurityAuditEntity> getList() {
		return this.securityAuditManagerBean.getAudit();
	}

	public void removeAll(ActionEvent actionEvent) {
		int removeCount = this.securityAuditManagerBean.removeAudit();
		FacesContext facesContext = FacesContext.getCurrentInstance();
		facesContext.addMessage(null, new FacesMessage(
				FacesMessage.SEVERITY_INFO, "Removed " + removeCount
						+ " security audit records.", null));
	}
}
